//
//  HelpView.m
//  Comma
//
//  Created by dlios on 15-1-13.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "HelpView.h"
#import "Masonry.h"
#import "GlobalMethod.h"
#import "GlobalMacro.h"
#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self;
@implementation HelpView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor whiteColor]];
        [self createButton];
        self.choicedButtonTag = -1;
    }
    return self;
}
- (void)createArray
{
    self.didSelectArr = @[@"Button_notice.pdf",@"Button_Activities.pdf", @"Button_Lecture.pdf", @"Button_Date.pdf", @"Button_Match.pdf", @"Button_Market.pdf", @"Button_Greedy.pdf", @"Button_Students.pdf", @"Button_lover.pdf", @"Button_Retrieve.pdf", @"Button_Help.pdf", @"Button_Nonsense.pdf"];
    self.selectArr = @[@"Button_notice_effect.pdf",@"Button_Activities_effect.pdf", @"Button_Lecture_effect.pdf", @"Button_Date_effect.pdf", @"Button_Match_effect.pdf", @"Button_Market_effect.pdf", @"Button_Greedy_effect.pdf", @"Button_Students_effect.pdf", @"Button_lover_effect.pdf", @"Button_Retrieve_effect.pdf", @"Button_Help_effect.pdf", @"Button_Nonsense_effect.pdf"];
    self.imgArr = @[@"mark_notice", @"mark_Activities", @"mark_Lecture", @"mark_Date", @"mark_Match", @"mark_Market", @"mark_Greedy", @"mark_Students", @"mark_lover", @"mark_Retrieve", @"mark_Help", @"mark_Nonsense"];
    self.textArr = @[@"学校的通知等信息",@"学校、社团、学生会等组织的活动信息", @"向同学们分享学校的讲座信息", @"约人创业、建设团、出去玩，约X等等。相约啥，就约啥", @"发布有关大学生的比赛信息，校内校外的都可以。非有关大学生的比赛不要在上面发布哦", @"大学生之间的物品交易市场，可以是全新的，也可以是二手的哦~", @"分享校园内食堂的美食信息，帮助那些每天去食堂不知道吃什么的童鞋们吧..", @"关于社团、学生会、工作室等的信息。例如：社团纳新、社团活动、社团交流等", @"找对象专用模块儿，不止是本校哦。也可以找外校的~~在这个模块儿只能发找对象的信息哦~~~~", @"丢东西了没地方儿发?捡到东西了也不知道去哪儿找失主？来豆号吧。", @"寻求帮助？或者想要帮助别人？快来求助吧，不要害羞哦~", @"社交模块儿。在这个模块儿下，想扯啥，咱就扯啥"];
}
- (void)createButton
{
    [self createArray];
    WS(weakSelf);
    self.backView = [UIView new];
    [self addSubview:self.backView];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (iPhone6) {
            make.edges.equalTo(weakSelf).with.insets(UIEdgeInsetsMake(SCREEN_HEIGHT - (598/2), 21.5, 31.5, 21.5));
        } else if (iPhone5) {
            make.edges.equalTo(weakSelf).with.insets(UIEdgeInsetsMake((SCREEN_HEIGHT - (598/2)) / 0.85, 21.5 * 0.85, 31.5 * 0.85, 21.5 * 0.85));
        } else if (iPhone6Plus) {
            make.edges.equalTo(weakSelf).with.insets(UIEdgeInsetsMake(SCREEN_HEIGHT/2, 12, 31.5, 20));

        }
    }];
    
    for (int i = 1; i <= 12; i++) {
        self.button = [[HelpButtonView alloc] initWithFrame:CGRectZero didSelectImg:[self.didSelectArr objectAtIndex:i - 1] selectImg:[self.selectArr objectAtIndex:i - 1]];
        self.button.tag = i + 100;
//        int width = (SCREEN_WIDTH - 32)/ 4;
        int width = 65;
//        int hight = (SCREEN_WIDTH - 32)/ 4;
        int hight = 80;
//        int gap = (SCREEN_HEIGHT - 667 - (SCREEN_WIDTH - 32)/ 4) / 2;
        int widthgap = 24;
        int hightgap = 16;
#warning ---
        if (iPhone5) {
            width = 65 * 0.85;
            hight = 80 * 0.85;
            widthgap = 24 * 0.85;
            hightgap = 16 * 0.85;
        }
        if (iPhone6Plus) {
            width = 65 * 1.2;
            hight = 80 * 1.2;
            widthgap = 24;
            hightgap = 16;
        }
        [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.backView addSubview:self.button];
        [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_backView.mas_top).with.offset((hight + hightgap) * ((i - 1) / 4));
            make.left.equalTo(_backView.mas_left).with.offset((width + widthgap)* ((i - 1)% 4));
            make.size.mas_equalTo(CGSizeMake(width, hight));
        }];
    }
    UIView *backView2 = [UIView new];
//    backView2.backgroundColor = [UIColor blackColor];
//    backView2.alpha = 0.6;
    [self addSubview:backView2];
    [backView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf).with.insets(UIEdgeInsetsMake(0, 16, SCREEN_HEIGHT - 667/2, 16));
        if (iPhone5) {
            make.edges.equalTo(weakSelf).with.insets(UIEdgeInsetsMake(0, 16, SCREEN_HEIGHT - 568 / 2, 16));
        }
        if (iPhone6Plus) {
            make.edges.equalTo(weakSelf).with.insets(UIEdgeInsetsMake(100, 16, SCREEN_HEIGHT - 568 / 2, 16));

        }
    }];
    self.titleLable = [UILabel new];
    self.titleLable.textAlignment = NSTextAlignmentCenter;
    self.titleLable.textColor = TEXTGREENCOLOR;
//    self.titleLable.font = BOLDDEFAULT_FONT(16.0f);
    self.titleLable.font = [UIFont boldSystemFontOfSize:16.0f];
    [self.titleLable setFont:[UIFont fontWithName:@"Helvetica" size:16.0f]];
    if (iPhone6Plus) {
//        self.titleLable.font = [UIFont boldSystemFontOfSize:17.0f];
    }
    self.titleLable.text = @"帮助";
    [backView2 addSubview:self.titleLable];
    [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf).with.offset(18);
        make.centerX.mas_equalTo(backView2.mas_centerX);
        make.top.equalTo(weakSelf).with.offset(10);
        make.centerX.mas_equalTo(self.mas_centerX);
        make.center.equalTo(self.titleLable);
        make.height.mas_equalTo(@44);
        make.width.mas_equalTo(@50);
        
#warning ---
        if (iPhone5) {
            make.top.equalTo(weakSelf).with.offset(30);
            make.centerX.mas_equalTo(backView2.mas_centerX);
            make.center.equalTo(self.titleLable);
            make.height.mas_equalTo(@(16 *0.85));
            make.width.mas_equalTo(@32);
        }
        if (iPhone6Plus) {
            make.top.equalTo(weakSelf).with.offset(30);
            make.centerX.mas_equalTo(backView2.mas_centerX);
            make.center.equalTo(self.titleLable);
            make.height.mas_equalTo(@(100 *1.656));
            make.width.mas_equalTo(@(100 * 1.656));
        }
        
    }];
    self.ImgView = [UIImageView new];
    self.ImgView.image = [UIImage imageNamed:@"mark_notice"];
    [self addSubview:self.ImgView];
    [self.ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backView2.mas_top).with.offset(100);
        make.centerX.mas_equalTo(backView2.mas_centerX);
        make.height.mas_equalTo(@135);
        make.width.mas_equalTo(@155);
#warning ---
        if (iPhone5) {
            make.top.equalTo(backView2.mas_top).with.offset(85);
            make.centerX.mas_equalTo(backView2.mas_centerX);
            make.height.mas_equalTo(@(135 * 0.85));
            make.width.mas_equalTo(@(155 * 0.85));
        }
//        if (iPhone6Plus) {
//            make.top.equalTo(backView2.mas_top).with.offset(85);
//            make.centerX.mas_equalTo(backView2.mas_centerX);
//            make.height.mas_equalTo(@(135 * 1.656));
//            make.width.mas_equalTo(@(155 * 1.656));
//        }
//
    }];

    
    self.introLable = [UILabel new];
    self.introLable.textColor = TEXTGREENCOLOR;
    self.introLable.text = @"嗨，有什么问题我可以帮助的！";
    self.introLable.textAlignment = NSTextAlignmentLeft;
//    self.introLable.font = DEFAULT_FONT(11.0f);
    [self.introLable setFont:[UIFont fontWithName:@"Helvetica" size:11.0f]];
    self.introLable.font = [UIFont boldSystemFontOfSize:11.0f];
    self.introLable.numberOfLines = 0;
    self.introLable.frame = CGRectMake(0, 0, SCREEN_WIDTH - 32, 0);
    [self.introLable sizeToFit];
    [self addSubview:self.introLable];
    [self.introLable mas_makeConstraints:^(MASConstraintMaker *make) {
        if (iPhone6) {
            make.bottom.equalTo(self.backView.mas_bottom).with.offset(- 598/2);
            make.left.equalTo(self.backView.mas_left).with.offset(0);
            make.right.equalTo(self.backView.mas_right).with.offset(-16);
        }
#warning ---
        if (iPhone5) {
            make.bottom.equalTo(self.backView.mas_bottom).with.offset(- 510/2);
            make.left.equalTo(self.backView.mas_left).with.offset(0);
            make.right.equalTo(self.backView.mas_right).with.offset(0);
        }
        if (iPhone6Plus) {
            make.bottom.equalTo(self.backView.mas_bottom).with.offset(- SCREEN_HEIGHT/2);
            make.left.equalTo(self.backView.mas_left).with.offset(0);
            make.right.equalTo(self.backView.mas_right).with.offset(0);
        }

    }];
//    [GlobalMethod drawLineWithStartPoint:CGPointMake(16, 677/2) EndPoint:CGPointMake(SCREEN_WIDTH, 677/2) inUIView:self];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(16, 677/2, SCREEN_WIDTH - 16, 0.5)];
#warning ---
    if (iPhone5) {
        view.frame = CGRectMake(16, 578 / 2, SCREEN_WIDTH - 16, 0.5);
    }
    if (iPhone6Plus) {
        view.frame = CGRectMake(16, SCREEN_HEIGHT / 2 - 20, SCREEN_WIDTH - 16, 0.5);
    }
    view.backgroundColor = LINEERGRAY;
    [self addSubview:view];
    self.backButton = [UIButton new];
    [self.backButton setBackgroundImage:[UIImage imageNamed:@"Button_close.png"] forState:UIControlStateNormal];
    [self addSubview:self.backButton];
    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf).with.offset(8);
        make.top.equalTo(weakSelf).with.offset(20);
        make.left.equalTo(backView2.mas_left).with.offset(0);
        make.top.equalTo(weakSelf).with.offset(10);
        make.height.mas_equalTo(@44);
        make.width.mas_equalTo(@44);
        
#warning ---
        if (iPhone5) {
            make.top.equalTo(weakSelf).with.offset(8);
            make.height.mas_equalTo(@(44*0.85));
            make.width.mas_equalTo(@(44*0.85));
        }
        if (iPhone6Plus) {
            make.top.equalTo(weakSelf).with.offset(8);
            make.height.mas_equalTo(@(44*1.656));
            make.width.mas_equalTo(@(44*1.656));

        }

    }];
}
- (void)buttonAction:(id)sender
{
//    [self createArray];
    HelpButtonView *buttonView = (HelpButtonView *)sender;
    self.ImgView.image = [UIImage imageNamed:[self.imgArr objectAtIndex:(buttonView.tag - 100 - 1)]];
    self.introLable.text = [self.textArr objectAtIndex:(buttonView.tag - 101)];
    [buttonView selectChangeState:YES];
    if (_choicedButtonTag == buttonView.tag) {
        return;
    }
    if (_choicedButtonTag != -1) {
        HelpButtonView * choicedButton = (HelpButtonView *)[self viewWithTag:_choicedButtonTag];
        [choicedButton selectChangeState:NO];
    }
    _choicedButtonTag = buttonView.tag;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
